<?php
@session_start();
require_once 'dataAccess.php';

$da = new dataAccess();

$type = intval($_POST['type']); // 0: book | 1: journal
$data['atitle'] = $_POST['assignment_title'];
$data['title1'] = $_POST['title1'];
$data['pub1'] = $_POST['pub1'];
$data['pcity1'] = $_POST['pcity1'];
$data['date1'] = $_POST['date1'];
$data['edition1'] = $_POST['edition1'];
$data['pages1'] = $_POST['pages1'];
$data['firstname1'] = $_POST['firstname1'];
$data['lastname1'] = $_POST['lastname1'];
$data['title2'] = $_POST['title2'];
$data['journal2'] = $_POST['journal2'];
$data['issue2'] = $_POST['issue2'];
$data['date2'] = $_POST['date2'];
$data['edition2'] = $_POST['edition2'];
$data['pages2'] = $_POST['pages2'];
$data['digital2'] = $_POST['digital2'];
$data['firstname2'] = $_POST['firstname2'];
$data['lastname2'] = $_POST['lastname2'];
$data['fileupload'] = $_POST['fileupload'];
$data['userid'] = intval($_POST['userid']);
$data['title_reference'] = intval($_POST['t_r']);
$_SESSION['tr_s'] = $data['title_reference'];
//print_r($data);exit;

// default: insert to composedocument_temp, then update immediately pdfterms depend on fileupload
// check if fileupload existed or not, not => insert, yes => update

$check = $da->checkFileUploadExist_ComposeTemp($data['fileupload'], $data['userid']);
if($num > 0) {
	$da->updateComposeTemp($type, $data);
} else {
	//$da->insertComposeTemp($type, $data);
	$da->insertComposeMain2($type, $data);
	$tempid = $da->last_inserted_id();
	//$da->updatePdfTerms_temp($tempid, $data['fileupload']);
	$da->updatePdfTerms_main($tempid, $data['fileupload']);
}
/*
if($_POST['title'] == "") {
	echo "0";
} else {
	echo "Good";
}
*/
?>